#! /usr/bin/env python
#coding:utf-8
#written by guolt;

import sys,os
from hashlib import md5

"""
squid push and del files!

cdn.tag文件状态说明：
1：正在上传；
2：上传完成；
3：正在分发；
4：分发完成；

"""
cdn_base='/u01/cdnLog'
tag_file=cdn_base+'/cdn.tag'
push_list=cdn_base+'/push.list'
del_list=cdn_base+'/del.list'
#download_dir="/usr/local/cdn_download"
cdn_log=cdn_base+'/cdn.log'
cdn_tmp=cdn_base+'/cdn_tmp/'
cdn_host_ip={'idc-cdn1.wuxi.jl':'58.215.80.133','idc-cdn2.wuxi.jl':'58.215.80.134'}
cdn_url="test.grandes.com.cn"



def getTag(self):
    tagfile=open(self,'r')
    for tag in tagfile.readlines():
        if tag.rstrip('\n') == '1':
            print "tag: 1."
        else:
            print "hello"



def del_file(self):
    """

    """
    for cdn_host,ip in cdn_host_ip.items():
        print cdn_host
        delFile=open(self,'r')
        for delList in delFile.readlines():
            delList=delList.rstrip('\n')
            print delList
            print u'开始purge url.........'
            print "hostname:%s DelFile: %s" %(cdn_host,delList)
            os.system('/usr/sbin/squidclient -h %s -p 80 -m PURGE http://%s/%s' %(cdn_host,cdn_url,delList))
                #print "###"*20
                #print delList
        delFile.close()

#getTag(tag_file)

del_file(del_list)
